import React, { useState, useEffect } from 'react';
import { Button, Tabs, Popconfirm } from 'antd';
import { LoadingOutlined } from '@ant-design/icons';
import {
  openNotification_util, checkdatavalid_util_formdata, fetchsync_util,
  resultdata_to_formdata, addkey_for_mxdata, use_dict_byzdmc, use_olreport_bybbbm,
  combile_mxdata_mxcol_util, convertISODateTimeToYYYYMMDDHHMMSS,
  view_item_util,
  checkdatavalid_util_formdata_mx,
} from '../util/util.js'
import Customfielditem_hook from '../newmes/customfielditem_hook.js'
import moment from 'moment'
import 'moment/locale/zh-cn'
import Xm_wlmx_hook from './xm_wlmx_hook.js';
import Xm_fjmx_hook from './xm_fjmx_hook.js';
import Xm_gysmx_hook from './xm_gysmx_hook.js';
import Xm_zbmx_hook from './xm_zbmx_hook.js';
import { SaveOutlined } from '@ant-design/icons';
import {
  use_xm_initformdata, use_xm_initformdata_view, use_xm_wlmx_column_initformdata, use_xm_fjmx_column_initformdata, use_xm_pbmd_column_initformdata,
  use_xmlx_gysmx_column_initformdata, use_xm_zbmx_column_initformdata, use_xm_gysfj_column_initformdata,
  use_gysyb_bjmx_column_initformdata
} from './use_zbzx_config.js';
moment.locale('zh-cn')
var storage = window.localStorage;
import useStore from '../../useStore.js'
import { dropByCacheKey } from 'react-router-cache-route'
import Xmkb_gysmx_hook from './xmkb_gysmx_hook .js';


const Xm_form = () => {
  //动态数据源
  const [dynDatasObject, setdynDatasObject] = useState({
    dict_zbxs: [], query_gys: [], query_ry: [], dict_jjgz: [], dict_wjlx: [], dict_cyqx: []
  })
  const [isloading, setisloading] = useState(true)
  const [wlmxdata, setwlmxdata] = useState([])
  const [fjmxdata, setfjmxdata] = useState([])
  const [gysmxdata, setgysmxdata] = useState([])
  const [zbmxdata, setzbmxdata] = useState([])
  const [gysfjdata, setgysfjdata] = useState([])
  const [gysbjdata, setgysbjdata] = useState([])
  const [pbmddata, setpbmddata] = useState([])
  const [wlmxcolums, setwlmxcolums] = useState(use_xm_wlmx_column_initformdata)
  const [fjmxcolums, setfjmxcolums] = useState(use_xm_fjmx_column_initformdata)
  const [gysmxcolums, setgysmxcolums] = useState(use_xmlx_gysmx_column_initformdata)
  const [zbmxcolums, setzbmxcolums] = useState(use_xm_zbmx_column_initformdata)
  const [gysfjcolums, setgysfjcolums] = useState(use_xm_gysfj_column_initformdata)
  const [gysbjcolums, setgysbjcolums] = useState(use_gysyb_bjmx_column_initformdata)
  const [pbmdcolums, setpbmdcolums] = useState(use_xm_pbmd_column_initformdata)
  const [wlmxdelidarr, setwlmxdelidarr] = useState([])
  const [fjmxdelidarr, setfjmxdelidarr] = useState([])
  const [gysmxdelidarr, setgysmxdelidarr] = useState([])
  const [zbmxdelidarr, setzbmxdelidarr] = useState([])
  const [gysfjdelidarr, setgysfjdelidarr] = useState([])
  const [gysbjdelidarr, setgysbjdelidarr] = useState([])
  const [pbmddelidarr, setpbmddelidarr] = useState([])
  const [supplierMap, setSupplierMap] = useState({}) //供应商名称映射
  const [activeKey, setactiveKey] = useState(1)
  /**
   * 强制刷新明细表 用于特殊场景
   */
  const [switche, setswitche] = useState(true);
  const forceupdate = () => { setswitche(false) }
  useEffect(() => { switche ? "1" : setswitche(true) }, [switche])

  const buildTree = (data) => {
    let treeData = []
    //一级分类数据
    let yjfl = data.filter(item => item.sjflid == '000')
    for (let i = 0; i < yjfl.length; i++) {
      //一级分类
      let yjflitem = { title: `(${yjfl[i].flbm})${yjfl[i].flmc}`, key: yjfl[i].flbm, value: yjfl[i].flmc, children: [] }
      //二级分类数据
      let ejfl = data.filter(item => item.sjflbm == yjfl[i].flbm)
      // console.log("ejfl", ejfl)
      for (let j = 0; j < ejfl.length; j++) {
        let ejflitem = { title: `(${ejfl[j].flbm})${ejfl[j].flmc}`, key: ejfl[j].flbm, value: ejfl[j].flmc, children: [] }
        let sjfl = data.filter(item => item.sjflbm == ejfl[j].flbm)
        for (let k = 0; k < sjfl.length; k++) {
          let sjflitem = { title: `(${sjfl[k].flbm})${sjfl[k].flmc}`, key: sjfl[k].flbm, value: sjfl[k].flmc }
          //往二级分类中添加二级分类
          ejflitem.children.push(sjflitem)
        }
        //往一级分类中添加二级分类
        yjflitem.children.push(ejflitem)
      }
      treeData.push(yjflitem)
    }
    return treeData
  };

  const init = async () => {
    setisloading(true)
    let rtdata = await fetchsync_util("/admin/baseinfo/wlfllb", 'POST', {}, "json")
    // console.log("rtdata", rtdata)
    var treedata = buildTree(rtdata.resultdata);
    var dictObj = await use_dict_byzdmc(["dict_zbxs", "dict_jjgz", "dict_wjlx", "dict_cyqx"])
    var bbObj = await use_olreport_bybbbm(["query_ry", "query_gys", "query_wl"])
    dynDatasObject.dict_zbxs = dictObj.dict_zbxs
    dynDatasObject.dict_jjgz = dictObj.dict_jjgz
    dynDatasObject.dict_wjlx = dictObj.dict_wjlx
    dynDatasObject.dict_cyqx = dictObj.dict_cyqx
    dynDatasObject.query_ry = bbObj.query_ry
    dynDatasObject.query_gys = bbObj.query_gys
    dynDatasObject.query_wl = bbObj.query_wl

    formdata.zbpl.selectdata = treedata
    setdynDatasObject({ ...dynDatasObject })
    setisloading(false)
  }

  //主表数据
  const [formdata, setformdata] = useState(JSON.parse(storage.pre_xm_kb_item).type != "view" ? use_xm_initformdata : use_xm_initformdata_view)
  const { setnowroute, collapsed } = useStore();

  // 供应商名称转换
  const transformSuppliers = (data) => {
    // 创建一个空的映射对象
    const supplierMap = {};
    // 创建一个字母表，用于生成供应商名称的后缀
    const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    let supplierIndex = 0;

    // 遍历原始数组，生成映射
    data.forEach(supplier => {
      if (!supplierMap[supplier.gysmc]) {
        // 生成新的供应商名称
        const supplierName = `供应商${alphabet[supplierIndex % alphabet.length]}`;
        supplierMap[supplier.gysmc] = supplierName;
        supplierIndex++;
      }
    });
    console.log(supplierMap, "supplierMap");
    setSupplierMap(supplierMap)
  }

  //加载主表数据
  const loadformdata = async (id) => {
    let rtdata = await fetchsync_util("/admin/zbzx/query_xm_byid_ls2", 'POST', { id }, "json")
    if (!rtdata.rtstatus) {
      openNotification_util("该项目不存在")
      return
    }
    rtdata.resultdata.formdata.create_time = rtdata.resultdata.formdata.create_time ? convertISODateTimeToYYYYMMDDHHMMSS(rtdata.resultdata.formdata.create_time) : ""
    rtdata.resultdata.formdata.update_time = rtdata.resultdata.formdata.update_time ? convertISODateTimeToYYYYMMDDHHMMSS(rtdata.resultdata.formdata.update_time) : ""
    rtdata.resultdata.formdata.sqsj = rtdata.resultdata.formdata.sqsj ? convertISODateTimeToYYYYMMDDHHMMSS(rtdata.resultdata.formdata.sqsj) : ""
    rtdata.resultdata.formdata.fbsj = rtdata.resultdata.formdata.fbsj ? convertISODateTimeToYYYYMMDDHHMMSS(rtdata.resultdata.formdata.fbsj) : ""
    rtdata.resultdata.formdata.ybjzsj = rtdata.resultdata.formdata.ybjzsj ? convertISODateTimeToYYYYMMDDHHMMSS(rtdata.resultdata.formdata.ybjzsj) : ""
    rtdata.resultdata.formdata.tbjzsj = rtdata.resultdata.formdata.tbjzsj ? convertISODateTimeToYYYYMMDDHHMMSS(rtdata.resultdata.formdata.tbjzsj) : ""
    rtdata.resultdata.formdata.pbkssj = rtdata.resultdata.formdata.pbkssj ? convertISODateTimeToYYYYMMDDHHMMSS(rtdata.resultdata.formdata.pbkssj) : ""
    rtdata.resultdata.formdata.pbjssj = rtdata.resultdata.formdata.pbjssj ? convertISODateTimeToYYYYMMDDHHMMSS(rtdata.resultdata.formdata.pbjssj) : ""
    rtdata.resultdata.formdata.kbsj = rtdata.resultdata.formdata.kbsj ? convertISODateTimeToYYYYMMDDHHMMSS(rtdata.resultdata.formdata.kbsj) : ""
    // rtdata.resultdata.formdata.gfkj = rtdata.resultdata.formdata.gfkj ? rtdata.resultdata.formdata.gfkj.split(",") : []
    // rtdata.resultdata.formdata.xfkj = rtdata.resultdata.formdata.xfkj ? rtdata.resultdata.formdata.xfkj.split(",") : []
    setformdata({ ...formdata, ...resultdata_to_formdata(rtdata.resultdata.formdata, formdata) });
    setwlmxdata(addkey_for_mxdata(rtdata.resultdata.wlmxdata))
    setzbmxdata(addkey_for_mxdata(rtdata.resultdata.zbmxdata))
    setgysmxdata(addkey_for_mxdata(rtdata.resultdata.gysmxdata.sort((a,b)=>b.zzdf-a.zzdf).map(item => {
      item.xzgys = item.gysmc
      item.sftt = item.ttyy ? "是" : "否"
      return item
    })))
    setfjmxdata(addkey_for_mxdata(rtdata.resultdata.fjmxdata))
    setpbmddata(addkey_for_mxdata(rtdata.resultdata.pbmddata))
    transformSuppliers(rtdata.resultdata.bjmxdata)
    setgysbjdata(addkey_for_mxdata(rtdata.resultdata.bjmxdata.map((item) => {
      item.bjsj = item.bjsj ? convertISODateTimeToYYYYMMDDHHMMSS(item.bjsj) : ""
      return item
    })))
    setgysfjdata(addkey_for_mxdata(rtdata.resultdata.gysfjmxdata.map((item) => {
      item.gys_fjscsj = item.gys_fjscsj ? convertISODateTimeToYYYYMMDDHHMMSS(item.gys_fjscsj) : ""
      return item
    })))
  }

  // 页面进入加载数据
  useEffect(() => {
    // if (JSON.parse(storage.pre_xm_kb_item).type == "edit" && JSON.parse(storage.pre_xm_kb_item).data.xmzt == "待发布") {
    //   loadformdata(JSON.parse(storage.pre_xm_kb_item).data.id)
    //   init()
    // }
    // else if (JSON.parse(storage.pre_xm_kb_item).type == "add") {
    //   init()
    // }
    // else if (JSON.parse(storage.pre_xm_kb_item).data.xmzt == "竞价结束") {
    //   loadformdata(JSON.parse(storage.pre_xm_kb_item).data.id)
    //   setwlmxcolums(view_item_util(use_xm_wlmx_column_initformdata()))
    //   setfjmxcolums(view_item_util(use_xm_fjmx_column_initformdata()))
    //   setgysmxcolums(view_item_util(use_xmlx_gysmx_column_initformdata()))
    //   setzbmxcolums(view_item_util(use_xm_zbmx_column_initformdata()))
    //   setgysfjcolums(view_item_util(use_xm_gysfj_column_initformdata()))
    //   setpbmdcolums(view_item_util(use_xm_pbmd_column_initformdata()))
    //   setisloading(false)
    // }
    // else {
    init()
    loadformdata(JSON.parse(storage.pre_xm_kb_item).data.id)
    setwlmxcolums(view_item_util(use_xm_wlmx_column_initformdata()))
    setfjmxcolums(view_item_util(use_xm_fjmx_column_initformdata()))
    setgysmxcolums(view_item_util(use_xmlx_gysmx_column_initformdata()))
    setzbmxcolums(view_item_util(use_xm_zbmx_column_initformdata()))
    setgysfjcolums(view_item_util(use_xm_gysfj_column_initformdata()))
    setpbmdcolums(view_item_util(use_xm_pbmd_column_initformdata()))
    setisloading(false)
    // }
  }, [])

  useEffect(() => {
    let newformdata = formdata
    //如果是竞价，根据项目状态显示竞价方面字段
    if (formdata.zbxs.value == "竞价") {
      newformdata.qz_title.inputType = "none"
      newformdata.swbqz.inputType = "none"
      newformdata.jsbqz.inputType = "none"
      newformdata.swbqz.bt = false
      newformdata.jsbqz.bt = false
      newformdata.jj_title.inputType = "title_item"
      newformdata.jjls.inputType = "view_item"
      newformdata.jjls.bt = false
      newformdata.mlcx.inputType = "view_item"
      newformdata.mlcx.bt = false
      newformdata.mljg.inputType = "view_item"
      newformdata.mljg.bt = false
      // newformdata.xfkj.inputType = "view_item"
      newformdata.gysbmjj.inputType = "view_item"
      newformdata.xmfbmjj.inputType = "view_item"
      newformdata.jjgz.inputType = "view_item"
      newformdata.jjgz.bt = false
      wlmxcolums.forEach(item => {
        if (item.dataIndex == "blje") {
          item.bt = false
        }
      })
      newformdata.swbqz.bt = false
      newformdata.jsbqz.bt = false
      newformdata.pbkssj.inputType = "none"
      newformdata.pbjssj.inputType = "none"
      // newformdata.blJe.inputType = "view_item"
      // newformdata.blJe.bt = false
    }

    else if (formdata.zbxs.value == "投标") {
      //竞价方面字段改成只读
      newformdata.qz_title.inputType = "title_item"
      newformdata.swbqz.inputType = "view_item"
      newformdata.jsbqz.inputType = "view_item"
      newformdata.swbqz.bt = false
      newformdata.jsbqz.bt = false
      newformdata.pbkssj.inputType = "view_item"
      newformdata.pbjssj.inputType = "view_item"
      newformdata.pbkssj.bt = false
      newformdata.pbjssj.bt = false
      newformdata.jj_title.inputType = "none"
      newformdata.jjls.inputType = "none"
      newformdata.jjls.bt = false
      newformdata.mlcx.inputType = "none"
      newformdata.mlcx.bt = false
      newformdata.mljg.inputType = "none"
      newformdata.mljg.bt = false
      // newformdata.xfkj.inputType = "view_item"
      newformdata.gysbmjj.inputType = "none"
      newformdata.xmfbmjj.inputType = "none"
      newformdata.jjgz.inputType = "none"
      newformdata.jjgz.bt = false
      wlmxcolums.forEach(item => {
        if (item.dataIndex == "blje") {
          item.bt = false
        }
      })
      // newformdata.blJe.inputType = "view_item"
      // newformdata.blJe.bt = false
    }
    //如果不是竞价，隐藏竞价方面字段
    else {
      newformdata.qz_title.inputType = "none"
      newformdata.swbqz.inputType = "none"
      newformdata.swbqz.bt = false
      newformdata.jsbqz.inputType = "none"
      newformdata.jsbqz.bt = false

      newformdata.jj_title.inputType = "none"
      newformdata.jjls.inputType = "none"
      newformdata.jjls.bt = false
      newformdata.mlcx.inputType = "none"
      newformdata.mlcx.bt = false
      newformdata.mljg.inputType = "none"
      newformdata.mljg.bt = false
      // newformdata.xfkj.inputType = "none"
      newformdata.gysbmjj.inputType = "none"
      newformdata.xmfbmjj.inputType = "none"
      newformdata.jjgz.inputType = "none"
      newformdata.jjgz.bt = false
      wlmxcolums.forEach(item => {
        if (item.dataIndex == "blje") {
          item.bt = false
        }
      })
      // newformdata.blJe.inputType = "none"
      // newformdata.blJe.bt = false
    }
    //如果项目已发布或者提交审核或者审核通过，不允许编辑项目
    if (formdata.xmzt.value != "待发布" || formdata.shzt.value == "审核通过" || formdata.shzt.value == "待审核") {
      newformdata.create_by.inputType = "view_item"
      newformdata.create_time.inputType = "view_item"
      newformdata.update_by.inputType = "view_item"
      newformdata.update_time.inputType = "view_item"
      newformdata.xmzt.inputType = "view_item"
      newformdata.xmbh.inputType = "view_item"
      newformdata.xmmc.inputType = "view_item"
      newformdata.zbpl.inputType = "view_item"
      // newformdata.cgpl.inputType = "view_item"
      newformdata.zbxs.inputType = "view_item"
      // newformdata.sqsj.inputType = "view_item"
      newformdata.fbsj.inputType = "view_item"
      newformdata.zbzrr.inputType = "view_item"
      newformdata.lxfs.inputType = "view_item"
      newformdata.ybjzsj.inputType = "view_item"
      // newformdata.tbjzsj.inputType = "view_item"
      newformdata.kbsj.inputType = "view_item"
      newformdata.xmjj.inputType = "view_item"
    }

    setformdata({ ...newformdata })
    if (JSON.parse(storage.pre_xm_kb_item).type == "edit" && JSON.parse(storage.pre_xm_kb_item).data.xmzt == "待发布") {
      setwlmxcolums(wlmxcolums)
    }
    else if (JSON.parse(storage.pre_xm_kb_item).type == "add") {
      setwlmxcolums(wlmxcolums)
    }
    else if (JSON.parse(storage.pre_xm_kb_item).data.xmzt == "竞价结束") {
      setwlmxcolums(view_item_util(wlmxcolums))
    }
    else {
      setwlmxcolums(view_item_util(wlmxcolums))
    }
    setswitche(false)

  }, [formdata.zbxs.value, formdata.xmzt.value])


  //设置value
  const setfield = (onekey, value, settype) => {
    if (settype == 'single') {
      if (onekey == "zbpl") {
        var newitem = formdata[onekey]
        newitem.value = value.value
        let newformdata = Object.assign({}, formdata, { [onekey]: newitem });
        setformdata(newformdata)
      }
      else {
        var newitem = formdata[onekey]
        newitem.value = value
        let newformdata = Object.assign({}, formdata, { [onekey]: newitem });
        setformdata(newformdata)
      }
    }
    else if (settype == "muti") {
      let [tansferarr, selectrow, newformdata] = [onekey, value, {}];
      tansferarr.forEach(item => {
        var newitem = formdata[item.target]
        newitem.value = selectrow ? selectrow[item.origin] : ""
        newformdata = Object.assign({}, formdata, { [item.target]: newitem });
      })
      setformdata(newformdata)
    }

  }

  //返回列表
  const handleBack = async () => {
    dropByCacheKey('xm_kb_form')
    dropByCacheKey('xm_kb_list')
    setnowroute({ route: "/shipSRM/zbzx/xm_kb_list", title: "遴选", closeroute: "/shipSRM/zbzx/xm_kb_form" })
  }

  //完成遴选
  const handleCompleteLx = async () => {
    try {
      let rtdata = await fetchsync_util("/admin/zbzx/complete_lx", 'POST', { 
        id: formdata.id.value,
        storage
      }, "json")
      if (rtdata.rtstatus) {
        openNotification_util("完成遴选成功")
        // 更新项目状态
        dropByCacheKey('xm_kb_form')
        dropByCacheKey('xm_kb_list')
        setnowroute({ route: "/shipSRM/zbzx/xm_kb_list", title: "遴选", closeroute: "/shipSRM/zbzx/xm_kb_form" })

      } else {
        openNotification_util(rtdata.rtmessage || "完成遴选失败")
      }
    } catch (error) {
      console.error('完成遴选失败:', error)
      openNotification_util("完成遴选失败")
    }
  }

  const renderfileditem = () => {
    var formdataarr = []
    for (var formitemkey in formdata) {
      formdata[formitemkey].inputType == "none" ? "" : formdataarr.push(formdata[formitemkey])
    }
    var renderstr = formdataarr.map(item => {
      var rtitem = item.input_type == "space_item" ?
        <Customfielditem_hook form={formdata} item={{ inputType: "none" }}
          handlechange={(key, value, settype) => { setfield(key, value, settype) }} />
        :
        <Customfielditem_hook form={formdata} item={formdata[item.dataIndex]}
          dynDatasObject={dynDatasObject}
          handlechange={(key, value, settype) => { setfield(key, value, settype) }} />
      return rtitem
    }
    )
    return renderstr
  }

  return (

    <div style={{
      height: "94%", backgroundColor: `#F1F1F1`, right: "1%", top: "5.9vh", overflow: "hidden",
      backgroundSize: "100% 100%", width: collapsed ? "94%" : "84%", position: "absolute", color: "white", fontSize: "0.8rem"
    }}
    data-page-type="form">

      <div style={{width:"100%",height:"100%",backgroundColor:"white",overflow:"auto"}}>
      <div style={{
        width: "100%", height: "7%", position: "sticky", top: "1%", backgroundColor: "white", color: "black", display: "flex",
        zIndex: 105, borderBottom: "2px solid #a91f24"
      }}>


        <div style={{ width: "40%", textAlign: "left", paddingRight: "1rem", display: "flex", alignItems: "center", fontWeight: "600" }}>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          工具栏
        </div>
        <div style={{ width: "60%", textAlign: "right", paddingRight: "1rem" }}>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          {/* 完成遴选按钮 - 仅在项目状态为遴选时显示 */}
          {formdata.xmzt.value === "遴选" && (
            <Popconfirm
              title="确定要完成遴选吗？"
              description="完成遴选后，项目状态将变为待竞价，此操作不可撤销。"
              onConfirm={handleCompleteLx}
              okText="确定"
              cancelText="取消"
              okButtonProps={{ danger: true }}
            >
              <Button 
                type="primary" 
                danger
                style={{ 
                  width: "8vw", 
                  height: '2.2vw', 
                  fontSize: "1vw", 
                  borderRadius: "5px", 
                  marginTop: "0.4vw",
                  marginRight: "1rem"
                }}
              >
                完成遴选
              </Button>
            </Popconfirm>
          )}
          <Button type="primary" onClick={() => { handleBack() }}
            style={{ width: "8vw", height: '2.2vw', fontSize: "1vw", borderRadius: "5px", marginTop: "0.4vw" }}>
            <SaveOutlined />返回列表</Button>

        </div>
      </div>

      <div style={styles.kshcontainer}>
        <div style={{
          fontSize: "0.7rem", position: "relative", width: "96%", marginLeft: "2%", backgroundColor: "", display: "flex",
          textIndent: "1rem", justifyContent: "flex-start", alignContent: "flex-start", flexWrap: "wrap", marginBottom: "2rem"
        }}>
          {renderfileditem()}
        </div>
        {/* 主表区域结束 */}
        {/* 物料明细区域*/}
        {/* <div style={{
          height: "1.2rem", marginLeft: "2%", position: "relative", width: "96%", textIndent: "0.5rem", color: "#666666",
          backgroundColor: "white", lineHeight: "1.2rem", fontSize: "14px", fontWeight: "500", textAlign: "left", borderLeftStyle: "solid",
          borderWidth: "0.3rem", borderColor: "#a91f24", marginTop: "1rem", marginBottom: "0.5rem", letterSpacing: "0.05rem"
        }}>
          物料明细
        </div>
        <div style={{
          fontSize: "0.7rem", position: "relative", width: "96%", marginLeft: "2%", backgroundColor: "", display: "flex",
          textIndent: "1rem", justifyContent: "flex-start", alignContent: "flex-start", flexWrap: "wrap"
        }}>
          {isloading ?
            (<div style={{ width: "10%", height: "10%", position: "absolute", left: "50%", top: "49%", color: "#14d9cc" }}>            <LoadingOutlined /></div>)
            :
            <div style={{ position: "relative", width: "100%", overflowX: "auto", marginBottom: "1rem" }}>
              {switche && <Xm_wlmx_hook colmuns={wlmxcolums} datasource={wlmxdata}
                styleobj={{ height: "70%" }}
                dynDatasObject={dynDatasObject}
                formdata={formdata}
                handledelid={ids => { ids.length !== 0 ? setwlmxdelidarr([...wlmxdelidarr, ...ids]) : ''; }}
                handgetmxdata={(tabledata) => {
                  addkey_for_mxdata(tabledata)
                  setwlmxdata(tabledata)
                }}
                ifshowaddbtn={JSON.parse(storage.pre_xm_kb_item).type != "view" && formdata.xmzt.value == "待发布" ? true : false}
                handlechangeFormdata={(data) => {
                  setformdata(data)
                }}
                forceupdate={forceupdate}
              />}</div>
          }
        </div> */}
        {/* 附件明细区域 */}
        {/* <div style={{
          height: "1.2rem", marginLeft: "2%", position: "relative", width: "96%", textIndent: "0.5rem", color: "#666666",
          backgroundColor: "white", lineHeight: "1.2rem", fontSize: "14px", fontWeight: "500", textAlign: "left", borderLeftStyle: "solid",
          borderWidth: "0.3rem", borderColor: "#a91f24", marginTop: "1rem", marginBottom: "0.5rem", letterSpacing: "0.05rem"
        }}>
          附件明细
        </div>
        <div style={{
          fontSize: "0.7rem", position: "relative", width: "96%", marginLeft: "2%", backgroundColor: "", display: "flex",
          textIndent: "1rem", justifyContent: "flex-start", alignContent: "flex-start", flexWrap: "wrap"
        }}>
          {isloading ?
            (<div style={{ width: "10%", height: "10%", position: "absolute", left: "50%", top: "49%", color: "#14d9cc" }}>            <LoadingOutlined /></div>)
            :
            <div style={{ position: "relative", width: "100%", overflowX: "auto", marginBottom: "1rem" }}>
              {switche && <Xm_fjmx_hook colmuns={fjmxcolums} datasource={fjmxdata}
                styleobj={{ height: "70%" }}
                dynDatasObject={dynDatasObject}
                formdata={formdata}
                handledelid={ids => { ids.length !== 0 ? setfjmxdelidarr([...fjmxdelidarr, ...ids]) : ''; }}
                handgetmxdata={(tabledata) => {
                  addkey_for_mxdata(tabledata)
                  setfjmxdata(tabledata)
                }}
                ifshowaddbtn={JSON.parse(storage.pre_xm_kb_item).type != "view" && formdata.xmzt.value == "待发布" ? true : false}
                handlechangeFormdata={(data) => {
                  setformdata(data)
                }}
                forceupdate={forceupdate}
              />}</div>
          }
        </div> */}
        {/* 供应商明细区域 */}
        <div style={{
          height: "1.2rem", marginLeft: "2%", position: "relative", width: "96%", textIndent: "0.5rem", color: "#666666",
          backgroundColor: "white", lineHeight: "1.2rem", fontSize: "14px", fontWeight: "500", textAlign: "left", borderLeftStyle: "solid",
          borderWidth: "0.3rem", borderColor: "#a91f24", marginTop: "1rem", marginBottom: "0.5rem", letterSpacing: "0.05rem"
        }}>
          供应商明细
        </div>
        <div style={{
          fontSize: "0.7rem", position: "relative", width: "96%", marginLeft: "2%", backgroundColor: "", display: "flex",
          textIndent: "1rem", justifyContent: "flex-start", alignContent: "flex-start", flexWrap: "wrap"
        }}>
          {isloading ?
            (<div style={{ width: "10%", height: "10%", position: "absolute", left: "50%", top: "49%", color: "#14d9cc" }}>            <LoadingOutlined /></div>)
            :
            <div style={{ position: "relative", width: "100%", overflowX: "auto", marginBottom: "1rem" }}>
              {wlmxdata.length > 0 && (
                <Tabs defaultActiveKey={activeKey} onChange={(key) => { setactiveKey(key) }} className='task-tabs' >
                  {Array.from({ length: wlmxdata.length }, (_, i) => (
                    <Tabs.TabPane tab={<span>{wlmxdata[i].wlmc}</span>} key={i + 1}>
                      {switche &&
                        <Xmkb_gysmx_hook colmuns={gysmxcolums}
                          datasource={addkey_for_mxdata(gysmxdata.filter(item => item.wlmxid == wlmxdata[i].id).map(
                            (item, index) => {
                              return {
                                ...item,
                                pm: index + 1
                              }
                            }
                          ))}
                          styleobj={{ height: "70%" }}
                          showcz={true}
                          dynDatasObject={dynDatasObject}
                          formdata={formdata}
                          handledelid={ids => { ids.length !== 0 ? setgysmxdelidarr([...gysmxdelidarr, ...ids]) : ''; }}
                          handgetmxdata={(tabledata) => {
                            addkey_for_mxdata(tabledata)
                            setgysmxdata(tabledata)
                          }}
                          calcolor={(text) => {
                            var color = "black"
                            if (text == '是') {
                              color = '#eb3617'
                            }
                            return color
                          }}
                          // ifshowaddbtn={JSON.parse(storage.pre_xm_kb_item).type != "view" && formdata.xmzt.value == "待发布" ? true : false}
                          handlechangeFormdata={(data) => {
                            setformdata(data)
                          }}
                          loadformdata={() => { loadformdata(JSON.parse(storage.pre_xm_kb_item).data.id) }}
                          forceupdate={forceupdate}
                        />}
                    </Tabs.TabPane>
                  ))}
                </Tabs>
              )}
            </div>
          }
        </div>
        {/* 评标委员明细区域 */}
        {/* <div style={{
          height: "1.2rem", marginLeft: "2%", position: "relative", width: "96%", textIndent: "0.5rem", color: "#666666",
          backgroundColor: "white", lineHeight: "1.2rem", fontSize: "14px", fontWeight: "500", textAlign: "left", borderLeftStyle: "solid",
          borderWidth: "0.3rem", borderColor: "#a91f24", marginTop: "1rem", marginBottom: "0.5rem", letterSpacing: "0.05rem"
        }}>
          评标委员明细
        </div>
        <div style={{
          fontSize: "0.7rem", position: "relative", width: "96%", marginLeft: "2%", backgroundColor: "", display: "flex",
          textIndent: "1rem", justifyContent: "flex-start", alignContent: "flex-start", flexWrap: "wrap"
        }}>
          {isloading ?
            (<div style={{ width: "10%", height: "10%", position: "absolute", left: "50%", top: "49%", color: "#14d9cc" }}>            <LoadingOutlined /></div>)
            :
            <div style={{ position: "relative", width: "100%", overflowX: "auto", marginBottom: "1rem" }}>
              {switche && <Xm_gysmx_hook colmuns={pbmdcolums} datasource={pbmddata}
                styleobj={{ height: "70%" }}
                dynDatasObject={dynDatasObject}
                formdata={formdata}
                handledelid={ids => { ids.length !== 0 ? setpbmddelidarr([...pbmddelidarr, ...ids]) : ''; }}
                handgetmxdata={(tabledata) => {
                  addkey_for_mxdata(tabledata)
                  setpbmddata(tabledata)
                }}
                ifshowaddbtn={JSON.parse(storage.pre_xm_kb_item).type != "view" && formdata.xmzt.value == "待发布" ? true : false}
                handlechangeFormdata={(data) => {
                  setformdata(data)
                }}
                forceupdate={forceupdate}
              />}</div>
          }
        </div> */}
        {/* 供应商附件明细区域 */}
        {/* {JSON.parse(storage.pre_xm_kb_item).type != "add" && <><div style={{
          height: "1.2rem", marginLeft: "2%", position: "relative", width: "96%", textIndent: "0.5rem", color: "#666666",
          backgroundColor: "white", lineHeight: "1.2rem", fontSize: "14px", fontWeight: "500", textAlign: "left", borderLeftStyle: "solid",
          borderWidth: "0.3rem", borderColor: "#a91f24", marginTop: "1rem", marginBottom: "0.5rem", letterSpacing: "0.05rem"
        }}>
          供应商附件明细
        </div>
          <div style={{
            fontSize: "0.7rem", position: "relative", width: "96%", marginLeft: "2%", backgroundColor: "", display: "flex",
            textIndent: "1rem", justifyContent: "flex-start", alignContent: "flex-start", flexWrap: "wrap"
          }}>
            {isloading ?
              (<div style={{ width: "10%", height: "10%", position: "absolute", left: "50%", top: "49%", color: "#14d9cc" }}>            <LoadingOutlined /></div>)
              :
              <div style={{ position: "relative", width: "100%", overflowX: "auto", marginBottom: "1rem" }}>
                {switche && <Xm_zbmx_hook colmuns={gysfjcolums} datasource={gysfjdata}
                  styleobj={{ height: "70%" }}
                  dynDatasObject={dynDatasObject}
                  formdata={formdata}
                  handledelid={ids => { ids.length !== 0 ? setgysfjdelidarr([...gysfjdelidarr, ...ids]) : ''; }}
                  handgetmxdata={(tabledata) => {
                    addkey_for_mxdata(tabledata)
                    setgysfjdata(tabledata)
                  }}
                  ifshowaddbtn={false}
                  handlechangeFormdata={(data) => {
                    setformdata(data)
                  }}
                  forceupdate={forceupdate}
                />}</div>
            }
          </div></>} */}
        {/* 供应商报价明细区域 */}
        {/* {JSON.parse(storage.pre_xm_kb_item).type != "add" && <><div style={{
          height: "1.2rem", marginLeft: "2%", position: "relative", width: "96%", textIndent: "0.5rem", color: "#666666",
          backgroundColor: "white", lineHeight: "1.2rem", fontSize: "14px", fontWeight: "500", textAlign: "left", borderLeftStyle: "solid",
          borderWidth: "0.3rem", borderColor: "#a91f24", marginTop: "1rem", marginBottom: "0.5rem", letterSpacing: "0.05rem"
        }}>
          供应商报价明细
        </div>
          <div style={{
            fontSize: "0.7rem", position: "relative", width: "96%", marginLeft: "2%", backgroundColor: "", display: "flex",
            textIndent: "1rem", justifyContent: "flex-start", alignContent: "flex-start", flexWrap: "wrap"
          }}>
            {isloading ?
              (<div style={{ width: "10%", height: "10%", position: "absolute", left: "50%", top: "49%", color: "#14d9cc" }}>            <LoadingOutlined /></div>)
              :
              <div style={{ position: "relative", width: "100%", overflowX: "auto", marginBottom: "1rem" }}>
                {switche && <Xm_zbmx_hook colmuns={gysbjcolums} datasource={gysbjdata}
                  styleobj={{ height: "70%" }}
                  dynDatasObject={dynDatasObject}
                  formdata={formdata}
                  handledelid={ids => { ids.length !== 0 ? setgysbjdelidarr([...gysbjdelidarr, ...ids]) : ''; }}
                  handgetmxdata={(tabledata) => {
                    addkey_for_mxdata(tabledata)
                    setgysbjdata(tabledata)
                  }}
                  handlechangeFormdata={(data) => {
                    setformdata(data)
                  }}
                  supplierMap={supplierMap}
                  ifshowaddbtn={false}
                  forceupdate={forceupdate}
                />}</div>
            }
          </div></>} */}
        {/* 中标区域 */}
        {/* {JSON.parse(storage.pre_xm_kb_item).type != "add" && <><div style={{
          height: "1.2rem", marginLeft: "2%", position: "relative", width: "96%", textIndent: "0.5rem", color: "#666666",
          backgroundColor: "white", lineHeight: "1.2rem", fontSize: "14px", fontWeight: "500", textAlign: "left", borderLeftStyle: "solid",
          borderWidth: "0.3rem", borderColor: "#a91f24", marginTop: "1rem", marginBottom: "0.5rem", letterSpacing: "0.05rem"
        }}>
          中标明细
        </div>
          <div style={{
            fontSize: "0.7rem", position: "relative", width: "96%", marginLeft: "2%", backgroundColor: "", display: "flex",
            textIndent: "1rem", justifyContent: "flex-start", alignContent: "flex-start", flexWrap: "wrap"
          }}>
            {isloading ?
              (<div style={{ width: "10%", height: "10%", position: "absolute", left: "50%", top: "49%", color: "#14d9cc" }}>            <LoadingOutlined /></div>)
              :
              <div style={{ position: "relative", width: "100%", overflowX: "auto", marginBottom: "1rem" }}>
                {switche && <Xm_zbmx_hook colmuns={zbmxcolums} datasource={zbmxdata}
                  styleobj={{ height: "70%" }}
                  dynDatasObject={dynDatasObject}
                  formdata={formdata}
                  handledelid={ids => { ids.length !== 0 ? setzbmxdelidarr([...zbmxdelidarr, ...ids]) : ''; }}
                  handgetmxdata={(tabledata) => {
                    addkey_for_mxdata(tabledata)
                    setzbmxdata(tabledata)
                  }}
                  ifshowaddbtn={false}
                  handlechangeFormdata={(data) => {
                    setformdata(data)
                  }}
                  forceupdate={forceupdate}
                />}</div>
            }
          </div></>} */}
      </div>
      </div>
    </div>
  )
}


export default Xm_form
var styles = {
  maincontainer: {
    height: "100vh", backgroundColor: `white`,
    backgroundSize: "100% 100%", width: "100%", position: "absolute", left: "0", color: "white", fontSize: "0.8rem"
  },
  topcontainer: {
    width: "100%", height: "10vw", backgroundImage: "linear-gradient(to bottom,#e4e5eb , white)", paddingTop: "3vw",
    position: "relative", fontSize: "0.89rem", textIndent: "2rem", fontWeight: "800", color: "#a91f24", borderRadius: "0 0 15px 15px"
  },
  butdcstyle: { paddingLeft: "1vw", paddingRight: "1vw", height: "2vw", position: "absolute", right: "1%", top: "0%", backgroundColor: "#a91f24", fontSize: "0.8vw", borderRadius: "0.4rem", borderRadius: "0 0 0.3vw 0.3vw" },
  butmainstyle: { paddingLeft: "1vw", height: "2vw", position: "absolute", right: "6.5%", top: "0%", backgroundColor: "#a91f24", fontSize: "0.8vw", borderRadius: "0.4rem", borderRadius: "0 0 0.3vw 0.3vw" },
  butbackstyle: { borderRadius: "0.4rem", backgroundColor: "#a91f24", height: "2vw", position: "absolute", right: "12%", top: "0%", fontSize: "0.8vw", borderRadius: "0 0 0.3vw 0.3vw" },
  kshcontainer: {
    width: "98%", position: "relative", backgroundColor: "white", color: "#666",
    borderRadius: "10px", paddingBottom: "2rem", overflow: "visible"
  },
}